<?php

namespace App\Http\Middleware;

use Closure;
use Route;
use Auth;

class CheckRbac
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (Auth::guard('admin')->user()->role_id !='1') {

            // var_dump(Auth::guard('admin')->user()->role_id);die;
            
            $route = Route::currentRouteAction();
           
            $ac = Auth::guard('admin')->user()->auth_ac;
                    
            $ac = strtolower($ac . ',indexcontroller@index,indexcontroller@welcome' );

            $routeArr = explode('\\',$route);
            if (strpos($ac, strtolower(end($routeArr))) === false) {
                exit('<h1>您没有权限</h1>');
                
            }
        }
       
       

        return $next($request);
    }
}
